package org.ttitfly.workflow.spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.ttitfly.workflow.factory.ObjectCreator;
import org.ttitfly.workflow.factory.ObjectNameUnavailableException;


/**
 * spring生成对象
 * 
 * @author 潘海春
 * @version 2010-12-24
 */
public class SpringBeanCreator implements ObjectCreator {

	/**
	 * 初始环境
	 */
	private BeanFactory beanFactory;

	/**
	 * 构造函数
	 * 
	 * @param props
	 */
	public SpringBeanCreator(BeanFactory beanFactory) {
		this.beanFactory = beanFactory;
	}

	@Override
	public Object createObject(String name)
			throws ObjectNameUnavailableException {
		try {
			return beanFactory.getBean(name);
		} catch (BeansException e) {
			throw new ObjectNameUnavailableException("不能在Spring容器中找到名称为[" + name + "]的Bean！", e);
		}
	}

}
